package jsu.xxy.coffee3.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
@RestController
public class UploadController {
    @PostMapping("/api/upload")
    public Map<String, String> uploadFile(@RequestParam("file") MultipartFile file) {
        String fileName = file.getOriginalFilename();
        String contentType = file.getContentType();
        long size = file.getSize();


// 按照需求进行文件校验，比如文件类型、大小等

        // 保存文件到本地或其他位置
        File destFile = new File("E:/picture/" + fileName);
        try {
            file.transferTo(destFile);
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 返回文件 URL 或其他信息
        Map<String, String> result = new HashMap<>();
        result.put("url", "http://192.168.182.117:5173/" + fileName);
        return result;
    }
}

